package com.xr.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xr.constant.MessageConstant;
import com.xr.pojo.Role;
import com.xr.query.QueryPageBean;
import com.xr.result.PageResult;
import com.xr.result.Result;
import com.xr.service.RoleService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("role")
public class RoleController {

    @Reference
    private RoleService roleService;

    @RequestMapping("/queryPage")
    public Result queryPage(@RequestBody QueryPageBean queryPageBean){
        try {
            PageResult page = roleService.findPage(queryPageBean);
            return new Result(true, MessageConstant.GET_ROLESETTING_SUCCESS,page);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(true, MessageConstant.GET_ROLESETTING_FAIL);
    }

    @RequestMapping("/add")
    public Result addSetMealCheckGroup(@RequestBody Role role , Integer [] PermissionIds){
        try {
            //1.添加套餐基础数据以及套餐与检查组的关联数据
            roleService.AddRolePermission(role,PermissionIds);
            return new Result(true,MessageConstant.ADD_ROLESETTING_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false,MessageConstant.ADD_ROLESETTING_FAIL);
    }
}
